package com.max.xihu.concurrent.day01;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author: Max
 * @Date: 2020-07-07 23:13
 * @Description:
 */
public class FairAndUnfairTest {

    private static Lock fairLock = new ReentrantLock2(true);
    private static Lock unfairLock = new ReentrantLock2(false);



    private static class Job extends Thread{

        private Lock lock;

        public Job(Lock lock){
            this.lock = lock;
        }

        @Override
        public void run(){
            System.out.println("当前线程状态:"+Thread.currentThread().getState());

        }
    }

    private static class ReentrantLock2 extends ReentrantLock{

        public ReentrantLock2(boolean fair){
            super(fair);
        }

        public Collection<Thread> getQuenedThreads(){
            List<Thread> arrayList = new ArrayList<>(super.getQueuedThreads());
            Collections.reverse(arrayList);
            return arrayList;
        }
    }
}
